package com.zxl.admin.controller.goods;

import com.github.pagehelper.PageInfo;
import com.zxl.admin.context.UserContext;
import com.zxl.common.Page;
import com.zxl.common.Result;
import com.zxl.common.model.bo.goods.GoodsTypeListBo;
import com.zxl.common.model.bo.goods.GoodsTypeSaveBo;
import com.zxl.common.model.pojo.SysGoodsType;
import com.zxl.common.service.SysGoodsTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author zxw
 * @date 2023/4/1
 */
@Api(tags = "商品分类管理")
@RestController
@RequestMapping("/admin/goods_type")
public class GoodsTypeController {

    @Resource
    private SysGoodsTypeService sysGoodsTypeService;

    @ApiOperation("新增分类")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid GoodsTypeSaveBo bo) {
        bo.setUserId(UserContext.getUserId());
        sysGoodsTypeService.add(bo);
        return Result.success();
    }


    @ApiOperation("修改分类")
    @PutMapping("/update")
    public Result update(@RequestBody @Valid GoodsTypeSaveBo bo) {
        bo.setUserId(UserContext.getUserId());
        sysGoodsTypeService.update(bo);
        return Result.success();
    }


    @ApiOperation("获取商品分类列表")
    @GetMapping("/actions/list")
    public Result<Page<SysGoodsType>> getGoodsList(GoodsTypeListBo bo) {
        List<SysGoodsType> list = sysGoodsTypeService.getList(bo);
        Page<SysGoodsType> page = Page.pageInfoConvert(new PageInfo(list));
        return new Result(page);
    }
}
